
def permutation(list):
    if len(list) == 1:
        return list
    else:
        ret = []
        for d in list:
            sub_list = list[:]
            sub_list.remove(d)
            ret += map(lambda s:d+s, permutation(sub_list))
        return ret

print permutation(map(str, range(10)))[999999]

